package com.neusoft.exception;

import com.neusoft.domain.Result;
import com.neusoft.domain.ResultCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

// @ControllerAdvice // 表明当前类是一个全局异常处理器
// @ResponseBody // 把返回的对象解析成json格式
@RestControllerAdvice
public class GlobalExceptionAdvice {

    /*未知异常处理*/
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e){
        e.printStackTrace();
        return Result.fail(ResultCode.UNKNOEN,"该功能正在建设中,请稍后重试");
    }

    /*对业务异常处理*/
    @ExceptionHandler(BusinessException.class)
    public Result handlerBusinessException(BusinessException e){
        // 记录日志,发送邮件
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}
